package com.pj.compose.ui.page.widget

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Popup
import androidx.navigation.NavController
import com.pj.compose.R
import com.pj.compose.ui.compose.*

@Composable
fun TipDialogPage(navController: NavController) {
    /**
     * 菜单列表
     */
    val listItems = listOf(
        "Loading类型提示框",
        "成功提示类型提示框",
        "失败提示类型提示框",
        "信息提示类型提示框",
        "单独图片类型提示框",
        "单独文字类型提示框",
        "自定义内容提示框",
    )
    val showTip = remember {
        mutableStateOf(false)
    }
    var tipType by remember {
        mutableStateOf(0)
    }
    AppTopBarColumn(
        title = "BottomSheet",
//            modifier = Modifier.padding(it),
        backClick = { navController.popBackStack() }) {
        SimpleListView(listItems) {
            tipType = it
            showTip.value = true
        }
        TipDialogs(show = showTip, type = tipType)
    }
}

@Composable
private fun TipDialogs(show: MutableState<Boolean>, type: Int) {
    val msg = listOf("正在加载", "发送成功", "发送失败", "请勿重复操作", "", "请勿重复操作", "自定义结构")[type]
    val icons = listOf(
        null,
        R.mipmap.icon_notify_done,
        R.mipmap.icon_notify_error,
        R.mipmap.icon_notify_info,
        R.mipmap.icon_notify_done,
        null
    )
    when (type) {
        0 -> {
            LoadingTip(show = show, msg = msg)
        }
        6 -> {
            BaseTipDialog(show = show, height = 60.dp, width = 180.dp) {
                Row(
                    modifier = Modifier
                        .fillMaxSize()
                        .padding(start = 15.dp),
                    horizontalArrangement = Arrangement.spacedBy(10.dp),
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Image(
                        painter = painterResource(id = R.mipmap.icon_notify_info),
                        contentDescription = "icon"
                    )
                    Text(text = msg, color = Color.White, fontSize = 16.sp)
                }
            }
        }
        else -> {
            val icon = icons[type]
            MessageTip(
                show = show,
                msg = msg,
                height = if (icon == null || msg.isEmpty()) 60.dp else 120.dp,
                iconId = icon
            )
        }
    }
}